#ifndef HISTORY_H
#define HISTORY_H

#include <QList>
#include <QListIterator>
#include <QDebug>

#include "command.h"

/**
 * @brief A Singleton class for storing the history of
 * commands used by the program.
 *
 * The history contains the commands used within our interface
 * so that they can be undone and redone.  There is only one
 * global history, so we use the Singleton pattern.
*/
class History : public QObject
{
    Q_OBJECT

private:
    //The constructor, copy constructor, and
    //assignment operators are all private
    History();
    Q_DISABLE_COPY(History)

    static History* _instance;

    QList<Command*>* _stack;
    QList<Command*>::iterator _stackPtr;

    //Calculates and emits the appropriate
    //status signal
    void emitStatus();

public:
    //Returns the one instance of the history
    //for use in the program
    static History* instance();

public slots:
    void undo();
    void redo();

    void push(Command* command);
    void clear();

signals:
    //Emitted after every change to the state with booleans indicating that you can
    //undo and/or redo. i.e., undo == true means that there are still things on the
    //history to undo. It also passes the "history tips", short descriptions about
    //the commands to undo/redo at the top of the history
    void status(bool undo, bool redo, QString undoTip, QString redoTip);
};

#endif // HISTORY_H
